package com.card.hwatt.controllers;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.card.hwatt.service.*;
import com.card.hwatt.assembler.HolidayAssembler;
import com.card.hwatt.dto.*;

/**
 * 节假日
 * @author Administrator
 *
 */
@Controller
@Scope("prototype")
@RequestMapping("/holiday")
public class HolidayController extends BaseController{

	@Autowired
	@Qualifier("holidayService")
	private HolidayService holidayService;

	@RequestMapping("/index")
	public String index() {
		return "holiday";
	}

	@RequestMapping("/save")
	public @ResponseBody
	ReturnValue save(@RequestBody List<String> list) {
		ReturnValue result = holidayService.save(list);
		return result;
	}

	@RequestMapping("/loadAll")
	public @ResponseBody
	List<HolidayYear> loadAll() {
		List<HolidayYear> list = HolidayAssembler
				.convertHolidayYearList(holidayService.loadAll());
		return list;
	}

	@RequestMapping("/create")
	public @ResponseBody
	HolidayYear create(int year) {
		List<Object> params = new ArrayList<Object>();
		params.add(year + "%");
		PageResult<com.card.hwatt.entity.Holiday> list = holidayService
				.loadAll(new PageParam(1, 1, " id like ? ", params, " id desc"));
		if (list != null && list.total > 0) {
			return null;
		}
		HolidayYear holidayYear = HolidayAssembler.create(year);
		return holidayYear;
	}

	@RequestMapping("/delete")
	public @ResponseBody
	ReturnValue delete(int year) {
		ReturnValue result = holidayService.deleteYear(year);
		return result;
	}
}
